package org.sith.gl.taskmanager.server;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import org.sith.gl.taskmanager.client.UsersRemoteService;
import org.sith.gl.taskmanager.client.beans.UserEntityGWT;
import org.sith.gl.taskmanager.server.db.dao.ApplicationContextKeeper;
import org.sith.gl.taskmanager.server.db.dao.UserEntity;
import org.sith.gl.taskmanager.server.db.service.UserService;
import org.sith.gl.taskmanager.server.util.Utils;

import java.util.ArrayList;
import java.util.List;


public class UsersRemoteServiceImpl extends RemoteServiceServlet implements UsersRemoteService {
    @Override
    public List<UserEntityGWT> getAllUsers() {

        UserService userService = (UserService) ApplicationContextKeeper.getApplicationContext().getBean("userService");
        List<UserEntity> list = userService.findAll();
        List<UserEntityGWT> result = new ArrayList<UserEntityGWT>();
        for (UserEntity userEntity : list) {
            result.add(Utils.convertToUserGWTEntity(userEntity));
        }

        return result;
    }


}